package org.dromara.system.controller.talent;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.ServiceItemRecordBo;
import org.dromara.system.domain.vo.ServiceItemRecordVo;
import org.dromara.system.service.IServiceItemRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务事项记录
 *
 * @author 毛宁川
 * @date 2025-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talent/ServiceItemRecord")
public class ServiceItemRecordController extends BaseController {

    private final IServiceItemRecordService serviceItemRecordService;

    /**
     * 查询服务事项记录列表
     */
    @SaCheckPermission("talent:ServiceItemRecord:list")
    @GetMapping("/list")
    public TableDataInfo<ServiceItemRecordVo> list(ServiceItemRecordBo bo, PageQuery pageQuery) {
        return serviceItemRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务事项记录列表
     */
    @SaCheckPermission("talent:ServiceItemRecord:export")
    @Log(title = "服务事项记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ServiceItemRecordBo bo, HttpServletResponse response) {
        List<ServiceItemRecordVo> list = serviceItemRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务事项记录", ServiceItemRecordVo.class, response);
    }

    /**
     * 获取服务事项记录详细信息
     *
     * @param serviceItemRecordId 主键
     */
    @SaCheckPermission("talent:ServiceItemRecord:query")
    @GetMapping("/{serviceItemRecordId}")
    public R<ServiceItemRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                          @PathVariable Long serviceItemRecordId) {
        return R.ok(serviceItemRecordService.queryById(serviceItemRecordId));
    }

    /**
     * 新增服务事项记录
     */
    @SaCheckPermission("talent:ServiceItemRecord:add")
    @Log(title = "服务事项记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServiceItemRecordBo bo) {
        return toAjax(serviceItemRecordService.insertByBo(bo));
    }

    /**
     * 修改服务事项记录
     */
    @SaCheckPermission("talent:ServiceItemRecord:edit")
    @Log(title = "服务事项记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServiceItemRecordBo bo) {
        return toAjax(serviceItemRecordService.updateByBo(bo));
    }

    /**
     * 删除服务事项记录
     *
     * @param serviceItemRecordIds 主键串
     */
    @SaCheckPermission("talent:ServiceItemRecord:remove")
    @Log(title = "服务事项记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceItemRecordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] serviceItemRecordIds) {
        return toAjax(serviceItemRecordService.deleteWithValidByIds(List.of(serviceItemRecordIds), true));
    }
}
